﻿using System;
using System.Data;
using System.Collections.Generic;

namespace LDSP.BRL
{
    public partial class ChemicalCatalog : BYFW.BOL.BaseEntity
    {
        private static IDictionary<int, string> _chemicalCatalogs = null;

        public ChemicalCatalog()
        {
            m_tableName = "t_chemicalCatalog";
            m_hasName = true;
            m_tblCacheManager.IsEnable = true;
        }

        protected string m_summary = string.Empty;
        protected string m_orgnization = string.Empty;
        protected DateTime m_publishDT = DateTime.MinValue;
        protected DateTime m_implementDT = DateTime.MinValue;

        /// <summary>
        /// 
        /// </summary>
        public string Summary
        {
            get { return m_summary; }
            set { m_summary = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Orgnization
        {
            get { return m_orgnization; }
            set { m_orgnization = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public DateTime PublishDT
        {
            get { return m_publishDT; }
            set { m_publishDT = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public DateTime ImplementDT
        {
            get { return m_implementDT; }
            set { m_implementDT = value; }
        }

        protected override void FillContainer()
        {
            base.FillContainer();
            m_container.Add("summary", m_summary);
            m_container.Add("orgnization", m_orgnization);
            m_container.Add("publishDT", m_publishDT);
            m_container.Add("implementDT", m_implementDT);
        }

        public override bool GetProperties(System.Data.DataRow record)
        {
            if (!base.GetProperties(record))
            {
                return false;
            }
            m_summary = this.GetStringValue(record, "summary");
            m_orgnization = this.GetStringValue(record, "orgnization");
            m_publishDT = this.GetDateValue(record, "publishDT");
            m_implementDT = this.GetDateValue(record, "implementDT");
            return true;
        }

        public string GetNameByID(int id)
        {
            string name = string.Empty;

            if (_chemicalCatalogs == null)
            {
                _chemicalCatalogs = new Dictionary<int, string>();

                List<ChemicalCatalog> ccs = new ChemicalCatalog().GetSpecialList<ChemicalCatalog>(null, null);
                foreach (ChemicalCatalog c in ccs)
                {
                    _chemicalCatalogs.Add(c.ID, c.Name);
                }
            }

            if (_chemicalCatalogs.ContainsKey(id))
            {
                name = _chemicalCatalogs[id];
            }

            return name;
        }
    }
}
